//
//  LoginVC.m
//  EducationLive
//
//  Created by Apple on 2017/10/16.
//  Copyright © 2017年 ZhouHao. All rights reserved.
//

#import "LoginVC.h"
#import "EducationLiveGloabl.h"
#import "RegisterVC.h"
#import "AuthCodeLoginVC.h"
#import "ForgetPasswordVC.h"
#import <UMSocialCore/UMSocialCore.h>

@interface LoginVC ()

@end

@implementation LoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // 加载导航栏item
    [self loadNavItem];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

#pragma mark - NavigationController Item Title
// 加载导航栏item
- (void)loadNavItem
{
    self.title = @"登录";
    
    [EducationLiveGloabl setNavButton:self imageName:nil setTitle:@"注册" setTitleColor:[UIColor whiteColor] titleSize:15 action:@selector(registerAction) withFrame:CGRectMake(0, 0, 30, 30) direction:@"right"];
}

- (void)registerAction
{
    RegisterVC *registerVC = [[RegisterVC alloc]init];
    [self.navigationController pushViewController:registerVC animated:YES];
}
#pragma mark - button Action
//验证码登录
- (IBAction)authCodeLoginAction:(UIButton *)sender
{
    AuthCodeLoginVC *authCodeLoginVC = [[AuthCodeLoginVC alloc]init];
    [self.navigationController pushViewController:authCodeLoginVC animated:YES];
}

//忘记密码
- (IBAction)forgetPasswordAction:(UIButton *)sender
{
    ForgetPasswordVC *forgetPasswordVC = [[ForgetPasswordVC alloc]init];
    [self.navigationController pushViewController:forgetPasswordVC animated:YES];
}

#pragma mark - Login
// QQ登录
- (IBAction)qqLoginAction:(UIButton *)sender
{
    [self getUserInfoForPlatform:UMSocialPlatformType_QQ];
}
// 新浪登录
- (IBAction)sinaLoginAction:(UIButton *)sender
{
    [self getUserInfoForPlatform:UMSocialPlatformType_Sina];
}
// 微信登录
- (IBAction)wechatLoginAction:(UIButton *)sender
{
    [self getUserInfoForPlatform:UMSocialPlatformType_WechatSession];
}

#pragma mark - UMengLoginAndShare
//友盟登录
- (void)getUserInfoForPlatform:(UMSocialPlatformType)platformType
{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:platformType currentViewController:self completion:^(id result, NSError *error) {
        if (error) {
            
        } else {
            UMSocialUserInfoResponse *resp = result;
            
            // 第三方登录数据(为空表示平台未提供)
            // 授权数据
            NSLog(@" uid: %@", resp.uid);
            NSLog(@" openid: %@", resp.openid);
            NSLog(@" accessToken: %@", resp.accessToken);
            NSLog(@" refreshToken: %@", resp.refreshToken);
            NSLog(@" expiration: %@", resp.expiration);
            
            // 用户数据
            NSLog(@" name: %@", resp.name);
            NSLog(@" iconurl: %@", resp.iconurl);
            NSLog(@" gender: %@", resp.unionGender);
            
            // 第三方平台SDK原始数据
            NSLog(@" originalResponse: %@", resp.originalResponse);
            alertView(@"登录成功");
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
